package com.lpinfo.spb.plateform.system.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lpinfo.spb.plateform.system.dto.SysMenuDto;
import com.lpinfo.spb.plateform.system.entity.SysMenu;
import com.lpinfo.spb.plateform.system.mapper.SysMenuMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

@Slf4j
@Transactional
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements  SysMenuService{

    @Override
    public IPage<SysMenu> page(Page<SysMenu> page, SysMenuDto params) {
        LambdaQueryWrapper<SysMenu> queryWrapper = new LambdaQueryWrapper<SysMenu>();

        if (!StringUtils.isEmpty(params)){
            queryWrapper.and(wrapper -> wrapper.like(SysMenu::getMenuName, params.getMenuName()));
        }
        if (!StringUtils.isEmpty(params)){
            //默认查询未删除的 1:正常 2:已删除
            queryWrapper.and(wrapper -> wrapper.like(SysMenu::getDeleteFlag, "1"));
        }
        ////根据不同的排序条件进行排序
        if(StringUtils.isEmpty(params.getSortField())){
            queryWrapper.orderByDesc(SysMenu::getCreateTime);
        }else{
            queryWrapper.orderByDesc(SysMenu::getCreateTime);
        }
        IPage<SysMenu> result= this.baseMapper.selectPage(page, queryWrapper);
        return result;
    }



}
